/**
 * 
 */
package vn.support.connection.response.processor.impl;

import java.util.Collection;
import org.apache.log4j.Logger;
import vn.support.connection.Connection;
import vn.support.connection.response.processor.AbstractResponseProcessor;
import vn.support.core.dto.ChatInfo;
import vn.support.core.dto.DataObject;
import vn.support.system.SystemProperties;
import vn.support.ui.ChatView;
import vn.support.ui.frame.ChatViewFrame;

/**
 * @author nttuyen
 *
 */
public class StaffChatProcessor extends AbstractResponseProcessor {

	private static final Logger log = Logger.getLogger(StaffChatProcessor.class);
	
    @Override
	public DataObject process(DataObject data) {
		String action = data.get(Connection.DTO_RESPONSE_ACTION);
		String xml = data.get(Connection.DTO_RESPONSE_DATA);
		if(action.equals(Connection.ACCEPT_CHAT_ACTION)) {
			Collection<ChatInfo> chats = this.entityFactory.create(xml, "//swiftwinapp", ChatInfo.class);
			for(ChatInfo chat : chats) {
				ChatViewFrame formChat = new ChatViewFrame(chat);
                DataObject system = SystemProperties.getData();
                system.set(ChatView.class.getName() + "#" + chat.getChatSessionId(), formChat);
                system.set(ChatView.class.getName() + "#" + chat.getVisitorSessionId(), formChat);
				formChat.setVisible(true);
			}
		}
		return data;
	}
	
}
